﻿<Window x:Class="DataLoader.UI.Views.MainView"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:Converters="clr-namespace:DataLoader.UI.Converters"
        xmlns:Core="clr-namespace:System;assembly=mscorlib"
        xmlns:Fenestra="clr-namespace:Fenestra;assembly=Fenestra"
        xmlns:CommonEnums="clr-namespace:DataLoader.Common.Enums;assembly=DataLoader.Common"
        xmlns:UIEnums="clr-namespace:DataLoader.UI.Misc"
        Icon="/Assets/SSISDestAdapter.ico"
        Title="Data Loader" 
        Height="600" Width="800">

    <Window.Resources>

        <Converters:YesNoConverter x:Key="YesNoConverter" />
        <Converters:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" />
        <Converters:IsBusyHasChangedMultiValueConverter x:Key="IsBusyHasChangedMultiValueConverter" />
        <Converters:BoolConverter x:Key="BoolConverter" />
        <Converters:BoolToDirtyConverter x:Key="BoolToDirtyConverter" />

        <ObjectDataProvider x:Key="SystemSourceEnum"  MethodName="GetValues" ObjectType="{x:Type Core:Enum}">
            <ObjectDataProvider.MethodParameters>
                <x:Type TypeName="CommonEnums:SourceSystem"/>
            </ObjectDataProvider.MethodParameters>
        </ObjectDataProvider>

        <ObjectDataProvider x:Key="ConfigSourceEnum"  MethodName="GetValues" ObjectType="{x:Type Core:Enum}">
            <ObjectDataProvider.MethodParameters>
                <x:Type TypeName="UIEnums:ConfigSource"/>
            </ObjectDataProvider.MethodParameters>
        </ObjectDataProvider>

        <ObjectDataProvider x:Key="YesNoEnum"  MethodName="GetValues" ObjectType="{x:Type Core:Enum}">
            <ObjectDataProvider.MethodParameters>
                <x:Type TypeName="UIEnums:YesNo"/>
            </ObjectDataProvider.MethodParameters>
        </ObjectDataProvider>

    </Window.Resources>

    <Grid x:Name="LayoutRoot">

        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>


        <GroupBox Grid.Row="0"  x:Name="Info" Header="User/Config Info" Height="80" Margin="5,5" >

            <StackPanel Orientation="Vertical" HorizontalAlignment="Left" VerticalAlignment="Top" 
                        IsEnabled="{Binding IsBusy, Converter={StaticResource BoolConverter}}"
                        Height="65" Margin="5,5,0,0" >

                <StackPanel Orientation="Horizontal" HorizontalAlignment="Left" Height="25" Margin="5,5" >
                    <TextBlock Height="25" Text="Logger in As: "  />
                    <TextBlock Height="25" Text="{Binding UserName}" Width="200" FontWeight="Bold"/>
                </StackPanel>

                <StackPanel Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Bottom" Height="30" Margin="5,-10" >
                    <TextBlock Height="20" Text="Config Used (Select): " VerticalAlignment="Top" Margin="0,5,0,0"/>
                    <ComboBox  Width="100" MinWidth="100" Height="20" Margin="0,-5,0,0"
                               SelectedItem="{Binding ConfigSource, UpdateSourceTrigger=LostFocus}"
                               ItemsSource="{Binding Source={StaticResource ConfigSourceEnum}}"/>
                </StackPanel>

            </StackPanel>
        </GroupBox>


        <GroupBox Grid.Row="1" x:Name="ConfigGroupBox" Header="Configuration Items" Margin="5,5" >

            <DataGrid 
                x:Name="ConfigDataGrid"
                ItemsSource="{Binding ConfigItems, Mode=TwoWay}" 
                IsEnabled="{Binding IsBusy, Converter={StaticResource BoolConverter}}"
                Margin="5,5" 
                AutoGenerateColumns="False"  
                CanUserReorderColumns="True" CanUserResizeColumns="True" 
                CanUserResizeRows="False" CanUserSortColumns="True">

                <DataGrid.CellStyle>
                    <Style TargetType="DataGridCell">
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding Path=IsDirty}" Value="True">
                                <Setter  Property="Background" Value="LightGoldenrodYellow"/>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </DataGrid.CellStyle>

                <DataGrid.Columns>

                    <DataGridComboBoxColumn Header="IsEnabled" Width="85" MinWidth="85"
                                            SelectedItemBinding="{Binding IsEnabled, Mode=TwoWay, UpdateSourceTrigger=LostFocus, Converter={StaticResource YesNoConverter}}"  
                                            ItemsSource="{Binding Source={StaticResource YesNoEnum}}"
                                            />

                    <DataGridComboBoxColumn Header="SourceSystem" Width="85" MinWidth="85"
                                            SelectedItemBinding="{Binding SourceSystem, Mode=TwoWay,  UpdateSourceTrigger=LostFocus}"
                                            ItemsSource="{Binding Source={StaticResource SystemSourceEnum}}"/>

                    <DataGridTextColumn Header="Source" IsReadOnly="True" 
                                        Binding="{Binding Source}" Width="SizeToCells"  MinWidth="85"/>

                    <DataGridTextColumn Header="Destination" IsReadOnly="True" 
                                        Binding="{Binding Destination}" Width="SizeToCells"  MinWidth="85"/>

                </DataGrid.Columns>


            </DataGrid>

        </GroupBox>


        <Fenestra:BizzySpinner Grid.Row="1"
                x:Name="BizzySpinner" 
                Spin="{Binding IsBusy}" 
                Angle="40"
                SpinRate="2"
                Width="40" 
                Height="40"                 
                Visibility="{Binding IsBusy, Converter={StaticResource BoolToVisibilityConverter}}"
                HorizontalAlignment="Center" 
                VerticalAlignment="Center"
                />


        <GroupBox Grid.Row="2" Name="Actions" Header="Actions" Height="60" Margin="5,5">
            <StackPanel Orientation="Horizontal"  HorizontalAlignment="Left" Height="25" Margin="5,5" >
                <Button Name="btnRefresh" Content="Refresh" Command="{Binding RefreshItemsCommand}" IsEnabled="{Binding IsBusy, Converter={StaticResource BoolConverter}}"/>
                <StackPanel Orientation="Horizontal"  HorizontalAlignment="Left" Height="25" Margin="5,0,0,0">
                    <StackPanel.Visibility>
                        <MultiBinding Converter="{StaticResource IsBusyHasChangedMultiValueConverter}">
                            <Binding Path="IsBusy" />
                            <Binding Path="IsDirty" />
                        </MultiBinding>
                    </StackPanel.Visibility>
                    <Button Name="btnUpdate"  Content="Update"  Command="{Binding UpdateItemsCommand}"  Height="25" />
                    <TextBlock Text="Denotes Updated Cells" Margin="5,0,0,0" Background="LightGoldenrodYellow" Foreground="Red" TextAlignment="Center" Height="18" />
                </StackPanel>
            </StackPanel>
        </GroupBox>


        <StatusBar Grid.Row="3" Height="25">
            <StatusBarItem>
                <TextBlock x:Name="StatusBar" Height="25" Text="{Binding StatusBarMessage}" />
            </StatusBarItem>
        </StatusBar>

    </Grid>

</Window>
